<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>购物超市</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" type="text/css" href="../static/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../static/bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
    <style>
        .header{
            width: 990px;
            height: 88px;
            margin: 0 auto;
        }
        .logo img{
            width: 190px;
            height: 88px;
            float: left;
            margin-right: 24px;
        }
        .logo-text{
            float: left;
            font-size: 18px;
            color: #666;
            line-height: 88px;
        }
        .main{
            width: 990px;
            margin: 0 auto;
            border: 1px solid #ddd;
            border-top: 3px solid #f90;
            background: #fff;
            padding: 110px 0;
            line-height: 1.5;
        }
        .reg-form{
            position: relative;
            width: 380px;
            margin: 0 auto;
        }
        .reg-a{
            position: relative;
            width: 380px;
            margin: 0 auto;
            padding: 0 50px;
        }
        .reg-a-l{
            position: relative;
        }
        .reg-a-r{
            position: relative;
            left: 165px;
            top: -43px;
            margin: 0 auto;
        }
        .input-box{
            width: 378px;
            height: 38px;
            border: 1px solid #ccc;
            line-height: 38px;
            margin-bottom: 25px;
        }
        .title{
            float: left;
            width: 76px;
            padding-left: 11px;
        }
        .input-box input{
            display: inline-block;
            width: 79%;
            height: 100%;
            font-size: 14px;
            color: #333;
            border: 0;
            background: 0;
            position: relative;
            padding: 0px 3px;
            margin: 0 auto;
            top: -1px;
        }
        .input-submit{
            width: 378px;
            height: 38px;
            border: 1px solid #ccc;
            line-height: 38px;
            margin-bottom: 25px;
        }
        .input-submit input{
            display: inline-block;
            width: 100%;
            height: 100%;
            font-size: 22px;
            color: white;
            border: 0;
            background: #ff7e00;
        }
        .input-submit input:hover{
            cursor: pointer;
            background: #ff5e03;
        }

        .reg-form span{
            margin: 0 auto;
            padding: 0 10px;
        }
    </style>
</head>
<body>
<div class="header">
    <a href="buserIndex.html" class="logo"><img src="photo/小猪折扣.png"></a>
    <div class="logo-text" >商家登录</div>
</div>

<div class="main">
    <div class="reg-a">
        <h2 class="reg-a-l"><a href="http://localhost:8080/loginNow">用户登录</a></h2>
        <h2 class="reg-a-r"><a href="http://localhost:8080/sLoginNow">商家登录</a></h2>
    </div>
    <form action="/suserLogin" method="post">
        <div class="reg-form">
            <div class="input-box" id="user">
                <label class="title">账号</label>
                <input type="text" name="username" id="name" placeholder="手机号/用户名" value="tom">
                <p style="color:#ff0000;position: relative;margin: -5px auto">{{msg}}</p>
            </div>
        </div>
        <div class="reg-form">
            <div class="input-box" id="pwd">
                <label class="title">密码</label>
                <input type="password" name="password" id="password" placeholder="请输入密码" value="123456">
                <p style="color:#ff0000;position: relative;margin: -5px auto">{{msg}}</p>
                <p th:text="${a}" style="color:#ff0000;position: relative;margin: -5px auto"></p>
            </div>
        </div>
        <div class="reg-form">
            <div class="input-submit">
                <input type="submit" id="sub" value="登录">
            </div>
        </div>
    </form>
    <div class="reg-form">
        <a href="http://localhost:8080/sRegNow">立即注册</a>
        <a href="http://localhost:8080/changeSuser">忘记密码</a>
    </div>
</div>
</body>
<script type="text/javascript" src="../static/bootstrap3/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/bootstrap.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/holder.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/html5shiv.min.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/css3-mediaqueries.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/respond.min.js"></script>
<script type="text/javascript" src="../static/js/vue.js"></script>
<script>

    let app1 = new Vue({
        el: "#user",
        data: {
            msg: ""
        }
    });
    //给用户名文本框添加失去焦点事件
    $("#name").blur(function () {
        //失去焦点时 通过ajax发出请求 检查用户名是否可用
        $.ajax({
            type:"get",
            url:"LoginSelUserName",
            data:"username="+$("#name").val(),
            success : function (msg) {
                app1.msg = msg;
                checkreg(msg);
            }
        });
    });

    let app2 = new Vue({
        el: "#pwd",
        data: {
            msg: ""
        }
    });
    //给用户名文本框添加失去焦点事件
    $("#password").blur(function () {
        //失去焦点时 通过ajax发出请求 检查用户名是否可用
        $.ajax({
            type:"get",
            url:"LoginPassword",
            data:"password="+$("#password").val(),
            success : function (msg) {
                app2.msg = msg;
                checkreg(msg);
            }
        });
    });


    function checkreg(str) {
        if ("用户名不存在"==str||"请输入密码"==str){
            $("#sub").prop("disabled",true);
        }else {
            $("#sub").prop("disabled",false);
        }
    }

</script>
</html>